<template>
	<view class="flex-col justify-start page">
		<view class="flex-col group_3">
			<map id="map" class="map" :show-location="true" :latitude="latitude" :longitude="longitude"></map>
			<view class="flex-col group_4">
				<view class="flex-row justify-between group_5" @click="getLocation()">
					<view class="flex-col self-center">
						<view class="flex-row self-stretch">
							<image class="shrink-0 self-center image_6" src="/static/icon/dingwei.png" />
							<text class="ml-12 self-start text_5">{{ position.name || '点击获取地址' }}</text>
							<!-- 	{{position}} -->
						</view>
						<text class="self-end text_6" style="margin-left:60rpx;">{{ position.address || '' }}</text>
					</view>
					<image class="self-start image_7" src="/static/icon/right.png" />
				</view>
				<view class="flex-row items-center group_6">
					<image class="image_6" src="/static/icon/fz.png" />
					<input style="margin-left:18rpx;font-size:26rpx;color:#000;"
						placeholder-style=" font-size:26rpx; font-family: PingFang SC; line-height: 30rpx; color: #999999;"
						v-model="floor" placeholder="请填写楼号、单元、门牌号" type="text" />
				</view>
				<view class="flex-row items-center group_7">
					<image class="image_8" src="/static/icon/luos.png" />
					<picker @change="bindPickerChange" :value="index" :range="array"  style="width:100%;">
						<text class="font_2 text_8 ml-13-5" v-if="index == -1"> 请选择搬入楼层 </text>
						<text class="font_2 text_8 ml-13-5" v-else style="color:#000;"> {{array[index]}} </text>
					</picker>
				</view>
				<!-- 		<view class="flex-row items-center group_8">
					<image class="image_6" src="/static/icon/dianhuas.png" />
					<input style="margin-left:18rpx;font-size:26rpx;color:#000;" maxlength="11"
						placeholder-style=" font-size:24rpx; font-family: PingFang SC; line-height: 30rpx; color: #999999;"
						v-model="phoen" placeholder="请输入联系电话" type="number" />
				</view> -->
				<view class="flex-row items-center group_9" style=" flex-wrap: wrap; margin-top:15rpx;">
					<text class="font_2 text_10" style="margin-top: 10rpx;">车辆停靠：</text>
					<view class="ml-10 flex-col justify-start items-center text-wrapper" style="margin-top: 10rpx;"
						:class="type == index ? 'coback':''" v-for="(item,index) in cartype" @click="botnav(index)">
						<view class="font_3 text_11">{{item}}</view>
					</view>
				</view>
			</view>
			<view class="flex-col justify-start items-center button text-wrapper_3" @click="tabqdadd">
				<text class="text_13">确认地址信息</text>
			</view>
			<!-- 	<view class="flex-col justify-start items-center button text-wrapper_3">
				<text class="text_13">确认地址信息</text>
			</view> -->
		</view>
	</view>
</template>

<script>
	import {
		BerthList,
		FloorList
	} from '@/utils/user.js'

	export default {




		data() {
			return {
				items: [null, null, null],

				latitude: 38.08364,
				longitude: 116.57828,



				yarray: [],
				addresname: "点击获取地址",
				addressname: "",

				array: [],
				// ['全程电梯  免费 ', '楼梯1层 20元', '楼梯2层 20元', '楼梯3层 30元'],


				cartype: [],
				// ['单元门口', '地下车库', '车库门口'],


				index: -1,

				type: 0,
				// 手机号
				phoen: '',
				// 楼层
				floor: '',
				// 位置信息
				position: {},



			}
		},
		onLoad(options) {

			// 楼层停靠

			this.Floorsandstops()
			// 获取传递的参数
			console.log(options)
			this.options = options


			console.log(this.options)
 
			var key = '';
			if (this.options.type == 0) {
				var key = "putong";
			} else if (this.options.type == 1) {
				var key = "rishi";
			} else if (this.options.type == 2) {
				var key = "qiye";
			}else if(this.options.type == 3){
				
				var key = "qwzlsn";
				
			}


			// 从本地缓存中获取大对象
			var storage = uni.getStorageSync(key) || {};




			if (this.options.initm == 1) {

				var s = storage.onew

			} else if (this.options.initm == 2) {


				var s = storage.two

			} else if (this.options.initm == 3) {

				var s = storage.three


			} else if (this.options.initm == 4) {

				var s = storage.four

			} if (this.options.initm == 5) {

				var s = storage.five

			}



			var dest = JSON.parse(s);
			console.log(dest, 'ssss')

			// type: this.type,
			// // 手机号
			// phoen: this.phoen,
			// // 楼层
			// floor: this.floor,
			// // 位置信息
			// position: this.position,
			// index: this.index,




			this.type = dest.type
			this.index = dest.index
			this.position = dest.position
			this.floor = dest.floor
			// this.phoen = dest.phoen
		},

		onReady() {


		},



		methods: {


			Floorsandstops() {
				var _this = this

				BerthList().then(res => {
					console.log(res)
					this.cartype = Object.values(res.data.data);
				}).catch(error => {
					console.error('BerthList 方法执行出错：', error);
				});

				FloorList().then(res => {
					console.log(res)

					this.yarray = Object.values(res.data.data);


					var arry = []
					this.yarray.forEach(function(obj) {
						arry.push(obj.title);
					});
					this.array = arry
				}).catch(error => {
					console.error('FloorList 方法执行出错：', error);
				});


			},


			tabqdadd() {
				// 判断位置信息

				if (this.position == {}) {
					uni.showToast({
						title: '请选择地址',
						icon: 'none',
						duration: 2000
					})

					return
				}


				// 详细地址
				if (this.floor == '') {
					uni.showToast({
						title: '请填写详细地址',
						icon: 'none',
						duration: 2000
					})

					return

				}





				// 判断楼层
				if (this.index == -1) {
					uni.showToast({
						title: '请选择楼层',
						icon: 'none',
						duration: 2000
					})

					return
				}


				// 判断手机号
				// const phoneNumber = this.phoen;
				// if (this.phoen == '') {
				// 	uni.showToast({
				// 		title: '手机号码为空',
				// 		icon: 'none',
				// 		duration: 2000
				// 	})
				// 	return
				// }
				// const regex = /^1(3[0-9]|4[01456879]|5[0-35-9]|6[2567]|7[0-8]|8[0-9]|9[0-35-9])\d{8}$/;
				// if (regex.test(phoneNumber)) {
				// } else {
				// 	console.log("手机号码格式不正确");
				// 	uni.showToast({
				// 		title: '手机号码有误',
				// 		icon: 'none',
				// 		duration: 2000
				// 	})
				// 	return
				// }


				// // 将数据存储到本地缓存中
				// uni.setStorageSync('myDataKey', dataToStore);


				// // 从本地缓存中读取之前存储的数据
				// const myData = uni.getStorageSync('myDataKey');


				// 判断 this.options 里的参数,



				var shuju = {


					type: this.type,
					// 手机号
					// phoen: this.phoen,
					// 楼层
					floor: this.floor,
					// 位置信息
					position: this.position,
					index: this.index,


				}







				// 假设 this.data 中包含了要存储的数据

				// 根据条件确定存储的键名
				console.log(this.options)

				var key = '';
				if (this.options.type == 0) {
					var key = "putong";
				} else if (this.options.type == 1) {
					var key = "rishi";
				} else if (this.options.type == 2) {
					var key = "qiye";
				} else if (this.options.type == 3) {
					var key = "qwzlsn";
				}



				// 从本地缓存中获取大对象
				var storage = uni.getStorageSync(key) || {};


				// 根据条件确定存储的值
				var value = {};

				var shujuJson = JSON.stringify(shuju);

				if (this.options.initm == 1) {
					var value = {
						onew: shujuJson
					};
				} else if (this.options.initm == 2) {
					var value = {
						two: shujuJson
					};
				} else if (this.options.initm == 3) {
					var value = {
						three: shujuJson
					};
				} else if (this.options.initm == 4) {
					var value = {
						four: shujuJson
					};
				}if (this.options.initm == 5) {
					var value = {
						five: shujuJson
					};
				}


				// 将数据存储到本地缓存中

				// 将对象转换为 JSON 字符串

				// 更新大对象中的小对象
				Object.assign(storage, value);

				// 将更新后的大对象存储到本地缓存中
				uni.setStorageSync(key, storage);


				// uni.setStorageSync(key, value);




				uni.navigateBack({
					delta: 1, // 返回页面数，这里返回上一页
					success() {
						// 返回成功后执行的操作
						uni.$emit('updateData', {
							options: '666666'
						});
					}
				});

	 




			},



			bindPickerChange: function(e) {
				console.log('picker发送选择改变，携带值为', e.detail.value)
				this.index = e.detail.value
			},

			// 地址解析
			dizhijiex() {




			},

			botnav(i) {
				this.type = i
			},






			tab() {
				uni.navigateTo({
					url: '/pages/Serviceaddress/Serviceaddress'
				})
			},

			getLocation() {
				var _this = this
				uni.chooseLocation({
					success: function(res) {
						console.log(res);


						_this.addresname = res.name
						_this.addressname = res.address
						_this.position = res
						console.log('位置名称：' + res.name);
						console.log('详细地址：' + res.address);
						console.log('纬度：' + res.latitude);
						console.log('经度：' + res.longitude);
					}
				});
			},
		}
	}
</script>

<style scoped>
	.coback {
		background-color: #2b8eff33 !important;
		color: #2b8eff !important;
	}

	.map {

		width: 100%;
		height: 350rpx;

	}

	input {

		width: 600rpx;

	}


	.ml-13-5 {
		margin-left: 27rpx;
	}

	.page {
		padding-bottom: 154rpx;
		background-color: #ffffff;
		width: 100%;
		overflow-y: auto;
		overflow-x: hidden;
		height: 100%;
	}

	.group_3 {
		padding: 21rpx 24rpx 80rpx;
		overflow-y: auto;
	}

	.image_5 {
		width: 93.6vw;
		height: 80vw;
	}

	.group_4 {
		margin-top: 46.08rpx;
		padding-top: 2.7rpx;
	}

	.group_5 {
		padding-bottom: 28.5rpx;
	}

	.image_6 {
		width: 36rpx;
		height: 36rpx;
	}

	.text_5 {
		color: #222222;
		font-size: 26rpx;
		font-family: PingFang SC;
		font-weight: 600;
		line-height: 22.6rpx;
	}

	.text_6 {
		margin-right: 21.94rpx;
		color: #666666;
		font-size: 22rpx;
		font-family: PingFang SC;
		line-height: 20.42rpx;
	}

	.image_7 {
		margin-right: 6rpx;
		margin-top: 13.22rpx;
		width: 23rpx;
		height: 23rpx;
	}

	.group_6 {
		padding: 26.5rpx 0;
		border-top: solid 1rpx #f4f5f7;
		border-bottom: solid 1rpx #f4f5f7;
	}

	.font_2 {
		font-size: 26rpx;
		font-family: PingFang SC;
		/* line-height: 22.34rpx; */
		color: #999999;
	}

	.text_7 {
		line-height: 22.42rpx;
	}

	.group_7 {
		padding: 29.56rpx 3.5rpx 31.44rpx;
		border-bottom: solid 1rpx #f4f5f7;
	}

	.image_8 {
		width: 30rpx;
		height: 28rpx;
	}

	.text_8 {
		line-height: 22.18rpx;
	}

	.group_8 {
		padding: 28.5rpx 0 24.5rpx;
		border-bottom: solid 1rpx #f4f5f7;
	}

	.text_9 {
		line-height: 22.2rpx;
	}

	.group_9 {
		padding: 0rpx 5.76rpx 9.5rpx;
	}

	.text_10 {
		color: #222222;
		line-height: 22.26rpx;
	}

	.text-wrapper {
		padding: 15.18rpx 0 14.52rpx;
		background-color: #f6f6f6;
		border-radius: 98rpx;
		width: 144rpx;
		color: #666666;
		height: 52rpx;
	}

	.font_3 {
		font-size: 26rpx;
		font-family: PingFang SC;
		line-height: 22.34rpx;
		/* color: #666666; */
	}

	.text_11 {
		line-height: 22.3rpx;
	}

	.text-wrapper_1 {
		padding: 15.2rpx 0 14.46rpx;
		background-color: #f6f6f6;
		border-radius: 98rpx;
		width: 144rpx;
		height: 52rpx;
	}

	.text-wrapper_2 {
		padding: 15.18rpx 0 14.44rpx;
		background-color: #f6f6f6;
		border-radius: 98rpx;
		width: 144rpx;
		height: 52rpx;
	}

	.text_12 {
		line-height: 22.38rpx;
	}

	.button {
		margin: 177.5rpx 28rpx 0;
	}

	.text-wrapper_3 {
		padding: 28.12rpx 0 28.22rpx;
		/* /* background-color: #2b8eff66; */

		background-color: #2b8eff;
		border-radius: 8rpx;
	}

	.text_13 {
		color: #ffffff;
		font-size: 36rpx;
		font-family: PingFang SC;
		line-height: 33.66rpx;
	}
</style>